﻿using System;
using Game1942.Library.Background;
using Game1942.Library.Background.Bodies;
using Game1942.Library.Planes;

namespace Game1942.Library.Items
{
    public class EnergyTank : ComputerElement
    {
        private Body body;
        private int lifeTime = Constants.EnergyTank.LifeTime;
        
        // Constructor
        public EnergyTank(Point value)
        {
            body = new Square(Constants.EnergyTank.Width, Constants.EnergyTank.Height);
            position.SetBody(body);
            position.InitializeLocation(value);
        }

        // Getter
        public int AmountOfEnergy
        {
            get { return Constants.EnergyTank.AmmountOfEnergy; }
        }

        public override void CrashWith(Element intruder)
        {
            var player = Driver.Instance.Player;
            if (ReferenceEquals(intruder, player))
            {
                player.ReloadEnergy(this);
                Destroy();
            }
        }

        public override int HarmSomebody(int enemyEnergy)
        {
            return enemyEnergy;
        }
        
        public override bool IsEnemy(Element intruder)
        {
            return (ReferenceEquals(intruder, Driver.Instance.Player));
        }

        public override bool IsEnemy(bool playerteam)
        {
            return false;
        }

        public override void Live()
        {
            if (lifeTime == 0)
            {
                Alive = false;
            }
            lifeTime--;

        }

        public override void Destroy()
        {
            position.Deallocate();  // If it is on the map, get rid of it
            Alive = false;
        }
    }
        
}
